#include <iostream>
#include <memory>
#include "udpServer.hpp"
#include "Dict.hpp"

using namespace DictNamespace;
void Usage(std::string pro)
{
    std::cout << "Usage:\n\t" << pro << "local_port\n";
}

//云服务器的端口号是默认禁止访问的。 云服务器开放端口8080~8085
int main(int argn, char* argv[])
{
    if (argn < 2)
    {
        Usage(argv[0]);
        exit(USAGE_ERROR);
    }
    //std::string ip = argv[1];

    EnableScreen();

    uint16_t port = std::stoi(argv[1]);

    // 定义翻译模块
    Dict dict;

    // 网络模块
    auto bound_function = std::bind(&Dict::Translate, &dict, std::placeholders::_1, std::placeholders::_2); //将成员函数绑定给另一个类
    std::unique_ptr<UdpServer> us_ptr = std::make_unique<UdpServer>(port, bound_function); 
    
    us_ptr->Init();
    us_ptr->Start();

    return 0;
}